class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Solution:
    cnt = 0
    ans = 0
    def kthLargest(self, root: TreeNode, k: int) -> int:
        
        def dfs(root):
            if root is None:
                return
            dfs(root.right)
            self.cnt+=1
            if self.cnt==k:
                self.ans = root.val
            dfs(root.left)
        dfs(root)
        return self.ans